package com.hxjc.bankagent.security;

import com.cmbc.afw.security.utils.SecurityUtil;
import com.cmbc.afw.utils.exception.RStatusException;
import com.cmbc.afw.utils.util.TxContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * SecurityHandler
 *
 * @author yinz
 * @date 2018/5/11
 */
public class SecurityHandler {

    static Logger logger = LoggerFactory.getLogger(SecurityHandler.class);

    public static String sign(String str) {
        String sgntr = null;
        String errCode = null ;
        try {
            sgntr = SecurityUtil.sign(str, "D:/test/cert/corp.sm2", "123123");
        } catch (Throwable t) {
            errCode = "XASFSECINB04";
            String errMsg = "入访响应报文签名操作失败";
            String msg = "错误代码:" + errCode + "，错误消息:" + errMsg;
            logger.error(msg);
            throw new RStatusException(errCode, errMsg, t);
        }
        return sgntr;
    }

    public static String encrypt(String str) {
        String cipherText = null;
        String errCode = null ;
        try {
            cipherText = SecurityUtil.encrypt(str, "D:/test/cert/cmbcTest.cer");
        } catch (Throwable t) {
            errCode = "XASFSECINB05";
            String errMsg = "入访响应报文加密操作失败";
            String msg = "错误代码:" + errCode + "，错误消息:" + errMsg;
            logger.error(msg);
            throw new RStatusException(errCode, errMsg, t);
        }
        return cipherText;
    }

}
